package com.gopay.common.util;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

public class MockHttpServletRequest extends HttpServletRequestWrapper {

	private Map<String, String> paramter = new HashMap<String, String>();

	@SuppressWarnings("rawtypes")
	public MockHttpServletRequest(HttpServletRequest request) {
		super(request);
		for (Enumeration enumeration = request.getParameterNames(); enumeration
				.hasMoreElements();) {
			String eleName = (String) enumeration.nextElement();
			String eleValue = request.getParameter(eleName);
			if (null == eleValue) {
				eleValue = "";
			}
			paramter.put(eleName, eleValue);
		}

	}

	@Override  
    public String getParameter(String name) {//重写getParameter，代表参数从当前类中的map获取  
        String values = paramter.get(name);  
        if(values == null || values.length() == 0) {  
            return "";  
        }  
        return values;  
    }  
}
